package com.lefevre.cms.service.platformShare.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.lefevre.cms.bean.platformShare.QuestionRewardPlatformShare;
import com.lefevre.cms.bean.platformShare.TopicUnhidePlatformShare;
import com.lefevre.cms.mapper.QuestionRewardPlatformShareMapper;
import com.lefevre.cms.mapper.TopicUnhidePlatformShareMapper;
import com.lefevre.cms.service.besa.DaoSupport;
import com.lefevre.cms.service.platformShare.PlatformShareService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 平台分成
 *
 * @author Lefevre
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class PlatformShareServiceImpl extends DaoSupport<TopicUnhidePlatformShare> implements PlatformShareService {

    @Resource
    private TopicUnhidePlatformShareMapper topicUnhidePlatformShareMapper;

    @Resource
    private QuestionRewardPlatformShareMapper questionRewardPlatformShareMapper;

    /**
     * 根据问题Id和回答问题的用户名称查询问答悬赏平台分成
     *
     * @param questionId     问题Id
     * @param answerUserName 回答问题的用户名称
     * @return
     */
    public QuestionRewardPlatformShare findQuestionRewardPlatformShareByQuestionIdAndAnswerUserName(Long questionId, String answerUserName) {
        return questionRewardPlatformShareMapper.selectOne(new LambdaQueryWrapper<QuestionRewardPlatformShare>()
                .eq(QuestionRewardPlatformShare::getQuestionId, questionId)
                .eq(QuestionRewardPlatformShare::getAnswerUserName, answerUserName));
    }


    /**
     * 删除问答悬赏平台分成
     *
     * @param questionId     问题Id
     * @param answerUserName 回答问题的用户名称
     * @return
     */
    public int deleteQuestionRewardPlatformShare(Long questionId, String answerUserName) {
        return questionRewardPlatformShareMapper.delete(new LambdaUpdateWrapper<QuestionRewardPlatformShare>()
                .eq(QuestionRewardPlatformShare::getQuestionId, questionId)
                .eq(QuestionRewardPlatformShare::getAnswerUserName, answerUserName));
    }

}
